package com.assets.room.dao;

import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.Query;
import androidx.room.Update;

import com.assets.room.entity.Asset;
import com.assets.room.entity.User;

import java.util.List;

@Dao
public interface AssetDao {

    @Insert
    void insertAsset(Asset asset);

    @Insert
    void insertAsset(List<Asset> asset);

    @Query("DELETE FROM t_asset_asset")
    void deleteAllData();

    @Query("SELECT asset_number FROM t_asset_asset WHERE rfid = :rfid")
    String queryById(String rfid);

    @Query("SELECT * FROM t_asset_asset WHERE status = :status")
    List<Asset> queryById1(String status);

    @Query("SELECT * FROM t_asset_asset WHERE status = :status1 OR status = :status2")
    List<Asset> queryById2(String status1, String status2);

    @Query("SELECT asset_id FROM t_asset_asset WHERE asset_number = :asset_number")
    Long queryByIds(String asset_number);

    @Query("SELECT * FROM t_asset_asset WHERE rfid = :rfid")
    Asset queryAllById(String rfid);

//    @Query("SELECT * FROM t_asset_asset WHERE asset_number = :asset_number")
//    Asset queryAllByIdSao(String asset_number);

    @Query("SELECT * FROM t_asset_asset WHERE asset_number = :asset_number")
    Asset queryAllByIdSao(String asset_number);

    @Query("SELECT * FROM t_asset_asset WHERE asset_id = :asset_id AND status = :status")
    List<Asset> queryAllByIds(String asset_id, String status);


    @Query("SELECT asset_id FROM t_asset_asset WHERE asset_id = :asset_id AND status = :status")
    List<Long> getAllByIds(String asset_id, String status);

    @Query("SELECT * FROM t_asset_asset WHERE asset_number = :asset_number")
    Asset getNumberByIds(String asset_number);


    @Query("SELECT * FROM t_asset_asset WHERE rfid = :rfid AND status = :status")
    List<Asset> queryAllByRfid(String rfid, String status);

    @Query("SELECT * FROM t_asset_asset WHERE asset_id = :asset_id")
    Asset queryAllByIds(String asset_id);

    @Query("SELECT * FROM t_asset_asset WHERE asset_number = :asset_number")
    Asset queryAllByNumber(String asset_number);

    @Query("UPDATE t_asset_asset SET status = :status, is_flag = :is_flag WHERE rfid = :rfid")
    void updateStatus(String status,String is_flag, String rfid);

    @Query("UPDATE t_asset_asset SET place = :place, is_flag = :is_flag, status = :status WHERE asset_number = :asset_number")
    void updatePlace(String place, String is_flag,String status, String asset_number);

    @Query("UPDATE t_asset_asset SET status = :status, is_flag = :is_flag WHERE asset_number = :asset_number")
    void updateStatusByNumber(String status,String is_flag, String asset_number);

    @Query("SELECT * FROM t_asset_asset WHERE is_flag = :is_flag")
    List<Asset> getAllAssetByStatus(String is_flag);

    @Update
    void updateAsset(Asset asset);

    @Query("SELECT * FROM t_asset_asset")
    List<Asset> getAllData();


//    @Query("SELECT * FROM t_asset_asset WHERE asset_id = :asset_id AND status = :status")
//    List<Asset> queryAllByIds(String asset_id,String status);

}
